<?php

namespace app\backend\controller;
//导入基类
use think\Controller;
use think\facade\Cache;
use think\Session;
use think\Db;
use think\Request;
use app\common\model\Operatelog;
use app\common\model\AdminUser;
class Login extends Controller 
{
	public function Index()
	{
		return $this->fetch();
	}

	public function check()
	{
		$name = input('post.name');
		$password = input('post.password', '', 'md5');
		/*$captcha = input('post.captcha');
		if (!captcha_check($captcha)) {

			$this->error('验证码错误');
		}*/

		$admin = AdminUser::where(['name' => $name, 'password' => $password])->find();

		if ($admin) {
			session('admin_id', $admin['id']);
			session('admin_name', $admin['name']);
			//写入登录日志
			$data['userid'] = $admin['id'];
			$data['ip_address'] = $_SERVER["REMOTE_ADDR"];
			$data['type'] = 1;
			$data['create_time'] = time();
			Operatelog::insert($data);
			$this->success('登陆成功', 'admin/index');
		}else{

			$this->error('密码错误');
		}

	}
	public function logout()
	{
		session('admin_id', null);
		session('admin_name', null);
		$this->success('退出成功', 'login/index');
	}
}